# coding: UTF-8

import urllib

class StaticMap:
    

    def __init__(self, appid):
        self.appid = appid
        self.url = 'http://map.olp.yahooapis.jp/OpenLocalPlatform/V1/static'
        self.params = {}
        self.params['appid'] = self.appid
        self.pins = {}

    def image(self, width, height, lat=None, lon=None, z=None):
        if lat:
            self.lat(lat)
        if lon:
            self.lon(lon)
        if z:
            self.z(z)

        self.params['width'] = width
        self.params['height'] = height
        
        lurl = self.url + '?'
        lurl +=  urllib.urlencode( self.params )
        
        return lurl

    def lat(self, lat):
        self.params['lat'] = lat
        return self
    
    def lon(self, lon):
        self.params['lon'] = lon
        return self

    def z(self, z):
        self.params['z'] = z
        return self

    def datum(self, datum):
        self.params['datum'] = datum
        return self

    def pin(self, lat, lon, index='', label='', color=''):
        pin = "pin%s"%(index)
        self.params[pin] = "%s,%s,%s,%s"%(lat,lon,label.encode('utf8'),color)
        return self
        


        
